//
//  UISearchBar+SPExtension.m
//  Sport
//
//  Created by Cass on 2017/11/17.
//  Copyright © 2017年 Cass. All rights reserved.
//

#import "UISearchBar+SPExtension.h"

@implementation UISearchBar (SPExtension)
- (void)setCancelButtonTitle:(NSString *)title{
    [[UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]] setTitle:title];
}
- (void)setCancelButtonFont:(UIFont *)font{
    [[UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]] setTitleTextAttributes:@{NSFontAttributeName:font} forState:UIControlStateNormal];
}
- (void)setSearchTextFieldTextColor:(UIColor *)textColor placeholderColor:(UIColor *)placeholderColor backgroundColor:(UIColor *)backgroundColor borderColor:(UIColor *)borderColor cornerRadius:(CGFloat)radius{
    [self setImage:[UIImage imageNamed:@"btn_sousuo_1"] forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];
    UITextField *searchTextField = [self valueForKey:@"searchField"];
    [searchTextField setBackgroundColor:backgroundColor];
    searchTextField.textColor = textColor;
    searchTextField.layer.borderColor = borderColor.CGColor;
    searchTextField.layer.borderWidth = 1.0f;
    [searchTextField setValue:placeholderColor forKeyPath:@"_placeholderLabel.textColor"];
    searchTextField.layer.cornerRadius = radius;
    searchTextField.layer.masksToBounds = YES;
}
- (void)setSearchTextFieldResignFirstResponder{
    UITextField *searchTextField = [self valueForKey:@"searchField"];
    [searchTextField endEditing:YES];
}
- (void)setTextColor:(UIColor *)textColor{
    [[UITextField appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]] setTextColor:textColor];
}
- (void)setTextFont:(UIFont *)font{
    [[UITextField appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]] setFont:font];
}
- (void)setPlaceholderColor:(UIColor *)placeHolderColor{
    [[UILabel appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]] setTextColor:placeHolderColor];
}
@end
